home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
FLAT.ZIP
/
FLATLIST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-09
|
15KB
|
508 lines
#define WIN31
#include <windows.h>
/* For the fancy looking Borland dialog box routines */
#ifdef USES_BWCC
#include <bwcc.h>
#endif
#include "flatm.h"
#pragma hdrstop
#include <string.h>
#include <stdlib.h>
#include "flatdata.h"
#include "flatfile.h"
#include "flatsort.h"
#include "flatsear.h"
#include "flatadd.h"
#include "\borlandc\winmem\memman.h"
#include "flatlist.h"
#ifdef USES_MEMCHECK
/* Memory checking routines by StratosWare Corp. */
#include "\wmemchec\memcheck.h"
#endif
/*--------------------------------------------
-
- FLATLIST.C
-
- Displays data records in a listbox.
- Uses WIN.INI info to format the date. Formating
- the currency is left up to you.
-
- Dennis R. Fischer
- Denam Systems
- 1115 Madison St. NE Suite 226
- Salem, Oregon 97303
-
- CompuServe 70405,1422
- Internet 70405.1422@compuserve.com
-
- Developed with Borland 3.1 Compiler
-
- Free for the taking but please give credit
- where credit is do
-
----------------------------------------------*/
char ts[255];
BOOL CALLBACK _export ListProc(HWND, UINT, WPARAM, LPARAM);
void _stuffstr (char *stuffer, int loc)
{
/* stuff a string into another string */
char s[81];
register int i, j;
i = loc;
if (i < 0) i = 0;
j = 0;
lstrcpy (s, stuffer);
while (s[j]) {
ts[i] = s[j];
i++;
j++;
}
} /* _stuffstr */
void SetListStr(struct tagFLATDATA *Flat)
{
/* Set the string that will be displayed in the
listbox to the data record
*/
char ts2[15];
char ts3[5];
/* Price */
lstrcpy(ts2, Flat->PriceDollar);
lstrcat(ts2, ".");
lstrcat(ts2, Flat->PriceCent);
_stuffstr(ts2, 11-(lstrlen(ts2)));
/* Invoice */
_stuffstr(Flat->Invoice, 12);
/* Date */
ts2[0] = (char)0;
ts3[0] = (char)0;
switch (GetDateFormat()) {
case DayMonYear:
if ((HasDayZero()) && (atoi(Flat->Day)) < 10)
lstrcat(ts2, "0");
lstrcat(ts2, Flat->Day);
lstrcat(ts2, GetDateMark());
if ((HasMonthZero()) && (atoi(Flat->Month) < 10))
lstrcat(ts2, "0");
lstrcat(ts2, Flat->Month);
lstrcat(ts2, GetDateMark());
lstrcat(ts3, Flat->Year);
if (lstrlen(ts3) >= 4) {
if (!HasCentury()) {
ts3[0] = ts3[2];
ts3[1] = ts3[3];
ts3[2] = (char)0;
}
}
lstrcat(ts2, ts3);
_stuffstr(ts2, 20);
break;
case YearMonDay:
lstrcat(ts2, Flat->Year);
if (lstrlen(ts2) >= 4) {
if (!HasCentury()) {
ts2[0] = ts2[2];
ts2[1] = ts2[3];
ts2[2] = (char)0;
}
}
lstrcat(ts2, GetDateMark());
if ((HasMonthZero()) && (atoi(Flat->Month) < 10))
lstrcat(ts2, "0");
lstrcat(ts2, Flat->Month);
lstrcat(ts2, GetDateMark());
if ((HasDayZero()) && (atoi(Flat->Day)) < 10)
lstrcat(ts2, "0");
lstrcat(ts2, Flat->Day);
_stuffstr(ts2, 20);
break;
default :
/* MonDayYear */
if ((HasMonthZero()) && (atoi(Flat->Month) < 10))
lstrcat(ts2, "0");
lstrcat(ts2, Flat->Month);
lstrcat(ts2, GetDateMark());
if ((HasDayZero()) && (atoi(Flat->Day)) < 10)
lstrcat(ts2, "0");
lstrcat(ts2, Flat->Day);
lstrcat(ts2, GetDateMark());
lstrcat(ts3, Flat->Year);
if (lstrlen(ts3) >= 4) {
if (!HasCentury()) {
ts3[0] = ts3[2];
ts3[1] = ts3[3];
ts3[2] = (char)0;
}
}
lstrcat(ts2, ts3);
_stuffstr(ts2, 20);
break;
}
/* Product */
_stuffstr(Flat->Product, 32);
/* Sold Ver */
_stuffstr(Flat->SoldVersion, 45);
/* Upgrade Ver */
_stuffstr(Flat->UpdateVersion, 50);
/* Company or Name */
if (lstrlen(Flat->Company) > 0)
_stuffstr(Flat->Company, 55);
else
_stuffstr(Flat->Name, 55);
/* State */
_stuffstr(Flat->State, 86);
/* Country */
_stuffstr(Flat->Country, 89);
ts[105] = (char)0;
} /* SetListStr */
BOOL FindStrs (LPCSTR lpFor, LPCSTR lpAt, BOOL bCaseSensitive)
{
/* Look for the search string that the user
indicated he wanted to look for
*/
BOOL bFound = TRUE;
BOOL bQuit, bQuit2;
char LookAt[(MAXDATASTR * 2)];
char LookFor[(MAXDATASTR * 2)];
char LookAtSave[(MAXDATASTR * 2)];
LPSTR pLookAt;
LPCSTR pLookFor;
LPCSTR p2p;
if (lstrlen(lpFor) > 0) {
bFound = FALSE;
lstrcpy(LookAt, lpAt);
lstrcpy(LookFor, lpFor);
lstrcpy(LookAtSave, lpAt);
pLookAt = &LookAt[0];
if (!bCaseSensitive) {
if (LookAt[0])
AnsiUpperBuff(LookAt, (UINT)lstrlen(LookAt));
if (LookAtSave[0])
AnsiUpperBuff(LookAtSave, (UINT)lstrlen(LookAtSave));
if (LookFor[0])
AnsiUpperBuff(LookFor, (UINT)lstrlen(LookFor));
}
bQuit = FALSE;
do{
lstrcpy(LookAt, LookAtSave);
pLookAt[lstrlen(LookFor)] = (char)0;
p2p = pLookAt;
pLookFor = &LookFor[0];
bQuit2=FALSE;
do{
if (p2p[0] == pLookFor[0]){
if (p2p[0] == (char)0) {
bQuit2 = TRUE;
bQuit = TRUE;
bFound = TRUE;
}
else {
p2p = AnsiNext(p2p);
pLookFor = AnsiNext(pLookFor);
}
}
else
bQuit2 = TRUE;
}while (!bQuit2);
pLookAt = AnsiNext(pLookAt);
if (pLookAt[0] == (char)0)
bQuit = TRUE;
}while(!bQuit);
}
return bFound;
}
void ShowSales(HWND hW)
{
/* Create the list box */
FARPROC fpList;
fpList = MakeProcInstance(ListProc, GetInstance());
if (fpList) {
DialogBox(GetInstance(), "DLG_LIST", hW, fpList);
FreeProcInstance(fpList);
}
}
#pragma argsused
BOOL CALLBACK _export ListProc(HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam) {
long recnum = 0l;
BOOL bQuit;
BOOL bUseit;
BOOL bGoodMem;
HFILE fhand;
int i;
int dateval;
WORD recsize;
static LRESULT nIndex;
char ts2[32];
LPCSTR lpcStr;
int dReadResult;
long lSeekResult;
static BOOL bNeverused;
int nError;
struct tagFLATDATA Flat;
TEXTMETRIC tm;
HDC hdc;
static int TotEntries;
int HeapErr;
long lBaseEntries;
switch(message) {
case WM_INITDIALOG:
SetCursor(LoadCursor(NULL, IDC_WAIT));
bNeverused = TRUE;
/* Set the window text */
switch (GetWork()) {
case DoEdit : SetWindowText(hDlg, "Edit Sales"); break;
case DoNew : SetWindowText(hDlg, "New Sale"); break;
case DoView : SetWindowText(hDlg, "View Sales"); break;
case DoDelete:SetWindowText(hDlg, "Delete Sale"); break;
default : SetWindowText(hDlg, "Error"); break;
}
/* turn off OK button */
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
/* Turn off list box redraw until everything is loaded
*/
SendDlgItemMessage(hDlg, DLG_LISTBOX, WM_SETREDRAW, TRUE, 0L);
/* Make listbox use fixed-sized font so
everything lines up. You could use set the tabs instead.
*/
SendDlgItemMessage(hDlg, DLG_LISTBOX, WM_SETFONT,
GetStockObject(SYSTEM_FIXED_FONT), 0L);
/* set width (in pixels) of listbox so user can
scroll the horizontal box
*/
hdc = GetDC(hDlg);
GetTextMetrics(hdc, &tm);
SendDlgItemMessage(hDlg, DLG_LISTBOX, LB_SETHORIZONTALEXTENT,
tm.tmAveCharWidth * 125, 0L);
ReleaseDC(hDlg, hdc);
/* Load list box with notices */
TotEntries=0;
SetCursor(LoadCursor(NULL, IDC_WAIT));
recnum = 0L;
recsize = (WORD)sizeof(Flat);
lBaseEntries = GetNumOfFlatRecords();
if (lBaseEntries)
HeapErr = CreateHeap((long)(sizeof(struct tagEVENTSORT) * (lBaseEntries + 1L)),
(int)(lBaseEntries + 1L));
if (lBaseEntries > 0L) {
if (HeapErr == IDE_OK) {
fhand = _lopen(flatfilename, OF_READ);
if (fhand != -1 ) {
ClearSortPtr();
bQuit = FALSE;
do{
bQuit =